﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Transactions;

namespace MySpiderMgr.Data.Sql
{
    public class SqlUnitOfWork : IUnitOfWork
    {
        static TransactionOptions transactionOptions = new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted };

        private TransactionScope _TransactionScope = null;

        public void BeginTran()
        {
            _TransactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions);
        }

        public void Commit()
        {
            if (_TransactionScope != null)
            {
                _TransactionScope.Complete();
                _TransactionScope = null;
            }
        }
        public void Dispose()
        {
            this._TransactionScope.Dispose();
            this._TransactionScope = null;
        }
    }
}
